


from fastapi import Request
from pydantic import BaseModel
from tortoise.transactions import atomic, in_transaction

from models.user import User
from service import UserService
from common.result.Result import Result
from common.enum import BaseEnum
from util.log import Log
from util.token import Token
from util.time import Time
from util.str import Str

async def HasUsername(req: Request, username: str):
    try:
        # 参数校验
        if Str.isBlank(username):
            Log.error('参数为空，检查参数')
            return Result.error(BaseEnum.PARAMETER_INVALID_ERROR)
        
        res = await UserService.hasUsername(username)
        if res == False:
            return Result.success(False)
        else:
            return Result.success(True)
    except Exception as e:
        Log.error('检查是否已存在 username', e)
        return Result.error(BaseEnum.SERVICE_ERROR)




